﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class Ingredients : System.Web.UI.Page
    {
        
        DataSet ds = new DataSet();
        SqlConnection con;
        SqlCommand cmd;
       

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        
        


        protected void ddlIngredients_SelectedIndexChanged(object sender, EventArgs e)
        {
 
        }

        protected void btnValider_Click(object sender, EventArgs e)
        {
  
            con= new SqlConnection("server=FORMA1614;Database=magicrecettes;User ID=magicrecettes;Password=cook;Trusted_Connection=False");
              
            cmd = new SqlCommand("dbo.submitrecord", con);
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
            cmd.Parameters.Add("@Nom", SqlDbType.VarChar, 50).Value = txtNom.Text;

            cmd.Parameters.Add("@Calories", SqlDbType.Int).Value = Int32.Parse(txtCalorie.Text);
            cmd.Parameters.Add("@Unite", SqlDbType.VarChar).Value = ddlIngredients.Text;

            try
            {
                cmd.ExecuteNonQuery();
                lblTest.Text = "Validé : " + ddlIngredients.SelectedValue;
                txtNom.Text = string.Empty;
                txtCalorie.Text = string.Empty;
                ddlIngredients.SelectedIndex = 0;
            }
            catch (SqlException ex)
            {
                Response.Write(ex.Message);
            }
            con.Close();

        }
    }
}